package com.blog.domain;

import java.io.Serializable;

import java.lang.StringBuilder;
import java.sql.Date;

import javax.persistence.Id;
import javax.persistence.NamedQueries;
import javax.persistence.NamedQuery;

import javax.xml.bind.annotation.*;

import javax.persistence.*;

/**
 */

@Entity
@NamedQueries({
		@NamedQuery(name = "findAllBlogs", query = "select myBlog from Blog myBlog"),
		@NamedQuery(name = "findBlogByContent", query = "select myBlog from Blog myBlog where myBlog.content = ?1"),
		@NamedQuery(name = "findBlogByDate", query = "select myBlog from Blog myBlog where myBlog.date = ?1"),
		@NamedQuery(name = "findBlogByDateContaining", query = "select myBlog from Blog myBlog where myBlog.date like ?1"),
		@NamedQuery(name = "findBlogById", query = "select myBlog from Blog myBlog where myBlog.id = ?1"),
		@NamedQuery(name = "findBlogByPrimaryKey", query = "select myBlog from Blog myBlog where myBlog.id = ?1"),
		@NamedQuery(name = "findBlogByReader", query = "select myBlog from Blog myBlog where myBlog.reader = ?1"),
		@NamedQuery(name = "findBlogByTitle", query = "select myBlog from Blog myBlog where myBlog.title = ?1"),
		@NamedQuery(name = "findBlogByTitleContaining", query = "select myBlog from Blog myBlog where myBlog.title like ?1") })
@Table(catalog = "blog", name = "blog")
@XmlAccessorType(XmlAccessType.FIELD)
@XmlType(namespace = "blog/com/blog/domain", name = "Blog")
public class Blog implements Serializable {
	private static final long serialVersionUID = 1L;

	/**
	 */

	@GeneratedValue(strategy = GenerationType.AUTO)
	@Column(name = "id", nullable = false)
	@Basic(fetch = FetchType.EAGER)
	@Id
	@XmlElement
	Integer id;
	/**
	 * 
	 * 
	 */

	@Column(name = "title", length = 50)
	@Basic(fetch = FetchType.EAGER)
	@XmlElement
	String title;
	/**
	 * 
	 * 
	 */

	@Column(name = "content", columnDefinition = "TEXT")
	@Basic(fetch = FetchType.EAGER)
	@Lob
	@XmlElement
	String content;
	/**
	 * 
	 * 
	 */
	
	@GeneratedValue(strategy = GenerationType.SEQUENCE)
	@Column(name = "date", length = 16)
	@Basic(fetch = FetchType.EAGER)
	@XmlElement
	Date date;
	/**
	 * 
	 * 
	 */

	@Column(name = "reader")
	@Basic(fetch = FetchType.EAGER)
	@XmlElement
	Integer reader;

	/**
	 */
	@ManyToOne(fetch = FetchType.LAZY)
	@JoinColumns({ @JoinColumn(name = "user_id", referencedColumnName = "id") })
	@XmlTransient
	User user;
	/**
	 */
	@ManyToOne(fetch = FetchType.LAZY)
	@JoinColumns({ @JoinColumn(name = "type_id", referencedColumnName = "id") })
	@XmlTransient
	Type type;

	public Integer getId() {
		return id;
	}

	public void setId(Integer id) {
		this.id = id;
	}

	public String getTitle() {
		return title;
	}

	public void setTitle(String title) {
		this.title = title;
	}

	public String getContent() {
		return content;
	}

	public void setContent(String content) {
		this.content = content;
	}

	public Date getDate() {
		return date;
	}

	public void setDate(Date date) {
		this.date = date;
	}

	public Integer getReader() {
		return reader;
	}

	public void setReader(Integer reader) {
		this.reader = reader;
	}

	public User getUser() {
		return user;
	}

	public void setUser(User user) {
		this.user = user;
	}

	public Type getType() {
		return type;
	}

	public void setType(Type type) {
		this.type = type;
	}

	/**
	 */
	public Blog() {
	}

	/**
	 * Copies the contents of the specified bean into this bean.
	 *
	 */
	public void copy(Blog that) {
		setId(that.getId());
		setTitle(that.getTitle());
		setContent(that.getContent());
		setDate(that.getDate());
		setReader(that.getReader());
		setUser(that.getUser());
		setType(that.getType());
	}

	/**
	 * Returns a textual representation of a bean.
	 *
	 */
	public String toString() {

		StringBuilder buffer = new StringBuilder();

		buffer.append("id=[").append(id).append("] ");
		buffer.append("title=[").append(title).append("] ");
		buffer.append("content=[").append(content).append("] ");
		buffer.append("date=[").append(date).append("] ");
		buffer.append("reader=[").append(reader).append("] ");

		return buffer.toString();
	}

	/**
	 */
	@Override
	public int hashCode() {
		final int prime = 31;
		int result = 1;
		result = (int) (prime * result + ((id == null) ? 0 : id.hashCode()));
		return result;
	}

	/**
	 */
	public boolean equals(Object obj) {
		if (obj == this)
			return true;
		if (!(obj instanceof Blog))
			return false;
		Blog equalCheck = (Blog) obj;
		if ((id == null && equalCheck.id != null) || (id != null && equalCheck.id == null))
			return false;
		if (id != null && !id.equals(equalCheck.id))
			return false;
		return true;
	}
}
